package com.dmooo.ymx.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.text.SpannableString;
import android.text.Spanned;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dmooo.ymx.R;
import com.dmooo.ymx.activity.JHSActivity;
import com.dmooo.ymx.bean.JdGoodsBean;
import com.dmooo.ymx.bean.MyGoodsResp;
import com.dmooo.ymx.bean.PhbBean;
import com.dmooo.ymx.common.SPUtils;
import com.dmooo.ymx.utils.StringUtils;
import com.dmooo.ymx.utils.VerticalImageSpan;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.text.DecimalFormat;
import java.util.List;

import jd.union.open.goods.query.request.GoodsReq;
import jd.union.open.goods.query.response.GoodsResp;

public class JDAdapterList extends CommonAdapter<MyGoodsResp> {
    SpannableString spannableString;
    Drawable drawable;
    DecimalFormat df = new DecimalFormat("0.00");
    private ShopRecyclerAdapter.OnDeleteClickLister mDeleteClickListener;

    public JDAdapterList(Context context, int layoutId, List<MyGoodsResp> datas) {
        super(context, layoutId, datas);
    }

    @Override
    protected void convert(ViewHolder holder, final MyGoodsResp item, int position) {
        ImageView imageView = holder.getView(R.id.image);
        if(item.imageInfo==null||item.imageInfo.getImageList().length==0){
            Glide.with(mContext).load("").placeholder(R.drawable.no_banner).dontAnimate().into(imageView);
        }else{
            Glide.with(mContext).load(item.imageInfo.getImageList()[0].getUrl()).placeholder(R.drawable.no_banner).dontAnimate().into(imageView);
        }
        spannableString = new SpannableString("   " + item.getSkuName());
        drawable = mContext.getResources().getDrawable(R.mipmap.label_jd);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        spannableString.setSpan(new VerticalImageSpan(drawable), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        ((TextView) holder.getView(R.id.title_child)).setText(spannableString);
        //券后2
        TextView tx2_2 = holder.getView(R.id.tx2_2);
        //设置删除线
        tx2_2.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        tx2_2.setText("原价:￥" + (item.pingGouInfo!=null?item.priceInfo.getPrice():0));
        //内部
        TextView tx3 = holder.getView(R.id.tx3);
        if(item.pingGouInfo==null||item.couponInfo.getCouponList().length==0){
            tx3.setText(0 + "");
        }else{
            tx3.setText(item.couponInfo.getCouponList()[0].getDiscount() + "");
        }
        TextView tx2 = holder.getView(R.id.tx2);
        try {
            tx2.setText("￥" + df.format(item.priceInfo.getPrice() - item.couponInfo.getCouponList()[0].getDiscount()));
        } catch (Exception e) {
            tx2.setText("￥" + df.format(item.priceInfo.getPrice()));
        }
        if(item.commissionInfo==null){
            holder.setText(R.id.tx4, "奖:0");
        }else{
            holder.setText(R.id.tx4, "奖:" + df.format(Double.valueOf(tx2.getText().toString().replace("￥",""))* Double.valueOf(df.format(item.commissionInfo.getCommissionShare()/100))*Double.parseDouble(df.format((float) SPUtils.getIntData(mContext, "rate", 0) / 100))));
        }
        if (item.getInOrderCount30Days() < 1000) {
            holder.setText(R.id.tx5, "销量:" + item.getInOrderCount30Days());
        } else {
            holder.setText(R.id.tx5, "销量:" + df.format((float) item.getInOrderCount30Days() / 10000) + "万");
        }
        holder.getView(R.id.tv_delete).setTag(position);
        holder.getView(R.id.tv_delete).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mDeleteClickListener != null) {
                    mDeleteClickListener.onDeleteClick(v, (Integer) v.getTag());
                }
            }
        });
    }
    public void setOnDeleteClickListener(ShopRecyclerAdapter.OnDeleteClickLister listener) {
        this.mDeleteClickListener = listener;
    }

    public interface OnDeleteClickLister {
        void onDeleteClick(View view, int position);
    }
}
